package com.esri.android.map.popup;

import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.net.Uri;
import android.text.TextUtils;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.core.internal.view.SupportMenu;
import androidx.viewpager.widget.PagerAdapter;
import com.esri.android.map.ags.ArcGISPopupInfo;
import com.esri.android.map.popup.ArcGISMediaAdapter;
import com.esri.core.geometry.ShapeModifiers;
import com.esri.core.map.popup.PopupImageMediaValue;
import com.esri.core.map.popup.PopupMediaInfo;
import java.text.DecimalFormat;
import org.achartengine.internal.GraphicalView;
import org.achartengine.internal.chart.k;
import org.achartengine.internal.model.ValueObject;
import org.achartengine.internal.model.b;
import org.codehaus.jackson.util.MinimalPrettyPrinter;

/* loaded from: classes.dex */
public class ArcGISMediaFullScreenPageAdapter extends PagerAdapter {
    ArcGISMediaAdapter a;
    Context b;

    public ArcGISMediaFullScreenPageAdapter(Context context, ArcGISMediaAdapter arcGISMediaAdapter) {
        this.a = arcGISMediaAdapter;
        this.b = context;
    }

    @Override // androidx.viewpager.widget.PagerAdapter
    public void destroyItem(ViewGroup viewGroup, int i, Object obj) {
        viewGroup.removeView((View) obj);
    }

    @Override // androidx.viewpager.widget.PagerAdapter
    public Object instantiateItem(ViewGroup viewGroup, int i) {
        if (this.a.a.a instanceof ArcGISPopupInfo) {
            PopupMediaInfo[] mediaInfos = this.a.a.a == null ? null : ((ArcGISPopupInfo) this.a.a.a).getMediaInfos();
            if (mediaInfos == null || mediaInfos.length <= 0) {
                return null;
            }
            a aVar = new a(this.b, i);
            viewGroup.addView(aVar);
            return aVar;
        }
        return null;
    }

    @Override // androidx.viewpager.widget.PagerAdapter
    public int getCount() {
        return this.a.getCount();
    }

    @Override // androidx.viewpager.widget.PagerAdapter
    public boolean isViewFromObject(View view, Object obj) {
        return ((a) obj) == view;
    }

    /* loaded from: classes.dex */
    private class a extends RelativeLayout {
        TextView a;
        TextView b;
        ScrollView c;

        /* JADX WARN: Multi-variable type inference failed */
        View a(ArcGISPopupStyle arcGISPopupStyle, final ArcGISMediaAdapter.MediaView mediaView, final int i) {
            TextView textView;
            if (mediaView.c() != null) {
                org.achartengine.internal.chart.a c = mediaView.c();
                if (c instanceof k) {
                    ((k) c).e().h(arcGISPopupStyle.getPopupBackgroundColor());
                }
                final GraphicalView graphicalView = new GraphicalView(getContext(), c);
                graphicalView.setGestureDetector(new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() { // from class: com.esri.android.map.popup.ArcGISMediaFullScreenPageAdapter.a.1
                    @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
                    public boolean onDown(MotionEvent motionEvent) {
                        return true;
                    }

                    @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnDoubleTapListener
                    public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
                        String str;
                        ValueObject a = graphicalView.a(motionEvent.getX(), motionEvent.getY());
                        if (a instanceof b) {
                            b bVar = (b) a;
                            TextView textView2 = a.this.b;
                            StringBuilder sb = new StringBuilder();
                            sb.append(bVar.a());
                            sb.append(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
                            sb.append(bVar.b());
                            if (Double.isNaN(bVar.c())) {
                                str = "";
                            } else {
                                str = " (" + new DecimalFormat("##.00").format(bVar.c() * 100.0d) + "%)";
                            }
                            sb.append(str);
                            textView2.setText(sb.toString());
                        } else {
                            a.this.b.setText(ArcGISMediaFullScreenPageAdapter.this.a.b.formatValue(ArcGISMediaFullScreenPageAdapter.this.a.getItem(i).getCaption(), null));
                        }
                        if (a.this.c != null) {
                            a.this.c.setVisibility(8);
                        }
                        a.this.b.invalidate();
                        return true;
                    }
                }));
                textView = graphicalView;
            } else if (mediaView.b() != null) {
                final ImageView imageView = new ImageView(getContext()) { // from class: com.esri.android.map.popup.ArcGISMediaFullScreenPageAdapter.a.2
                    GestureDetector a = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() { // from class: com.esri.android.map.popup.ArcGISMediaFullScreenPageAdapter.a.2.1
                        @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
                        public boolean onDown(MotionEvent motionEvent) {
                            return true;
                        }

                        @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnDoubleTapListener
                        public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
                            String formatValue = ArcGISMediaFullScreenPageAdapter.this.a.b.formatValue(ArcGISMediaFullScreenPageAdapter.this.a.a.mFeatureType, ((PopupImageMediaValue) ArcGISMediaFullScreenPageAdapter.this.a.getItem(i).getValue()).getLinkURL(), null);
                            if (formatValue == null || formatValue.length() <= 0) {
                                return true;
                            }
                            Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(formatValue));
                            intent.addFlags(ShapeModifiers.ShapeHasIDs);
                            getContext().getApplicationContext().startActivity(intent);
                            return true;
                        }
                    });

                    @Override // android.view.View
                    public boolean onTouchEvent(MotionEvent motionEvent) {
                        return this.a.onTouchEvent(motionEvent);
                    }
                };
                if (!ArcGISMediaAdapter.MediaView.STATUS.LOADED.equals(mediaView.g())) {
                    imageView.setImageDrawable(new ProgressBar(getContext()).getProgressDrawable());
                    mediaView.l = new ArcGISMediaAdapter.MediaView.LoadStatusListener() { // from class: com.esri.android.map.popup.ArcGISMediaFullScreenPageAdapter.a.3
                        @Override // com.esri.android.map.popup.ArcGISMediaAdapter.MediaView.LoadStatusListener
                        public void onLoadStatusChanged(ArcGISMediaAdapter.MediaView.STATUS status) {
                            imageView.setImageBitmap(mediaView.b());
                        }
                    };
                } else {
                    imageView.setImageBitmap(mediaView.b());
                }
                imageView.setId(4);
                textView = imageView;
            } else {
                TextView textView2 = new TextView(getContext());
                textView2.setGravity(17);
                textView2.setText(mediaView.d());
                textView2.setTextColor(SupportMenu.CATEGORY_MASK);
                textView2.setTypeface(Typeface.DEFAULT_BOLD);
                textView2.setTextSize(1, 30.0f);
                textView = textView2;
            }
            textView.setId(4);
            return textView;
        }

        public a(Context context, final int i) {
            super(context);
            final RelativeLayout.LayoutParams layoutParams;
            View a;
            final ArcGISPopupStyle arcGISPopupStyle = (ArcGISPopupStyle) ArcGISMediaFullScreenPageAdapter.this.a.a.getLayout().getStyle();
            setBackgroundColor(arcGISPopupStyle.getPopupBackgroundColor());
            setGravity(16);
            TextView textView = new TextView(getContext());
            this.a = textView;
            textView.setId(1);
            TextView textView2 = new TextView(getContext());
            this.b = textView2;
            textView2.setId(2);
            this.c = new ScrollView(getContext());
            this.a.setTextSize(1, arcGISPopupStyle.getMediaFullScreenTitleFontSize());
            this.a.setTypeface(arcGISPopupStyle.getMediaFullScreenTitleFontType(), arcGISPopupStyle.getMediaFullScreenTitleFontStyle());
            this.a.setTextColor(arcGISPopupStyle.getMediaFullScreenTitleColor());
            this.a.setText(ArcGISMediaFullScreenPageAdapter.this.a.b.formatValue(ArcGISMediaFullScreenPageAdapter.this.a.a.mFeatureType, ArcGISMediaFullScreenPageAdapter.this.a.getItem(i).getTitle(), null));
            this.a.setGravity(17);
            this.a.setLines(2);
            RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(-1, PopupUtil.convertDpInPixels(ArcGISMediaFullScreenPageAdapter.this.b, 80));
            layoutParams2.alignWithParent = true;
            addView(this.a, layoutParams2);
            final ArcGISMediaAdapter.MediaView mediaView = ArcGISMediaFullScreenPageAdapter.this.a.mMediaViewCache.get(i);
            if (mediaView.g() == ArcGISMediaAdapter.MediaView.STATUS.NOT_LOADED) {
                mediaView.a();
            }
            RelativeLayout.LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(-2, -2);
            layoutParams3.alignWithParent = false;
            layoutParams3.addRule(3, this.a.getId());
            layoutParams3.addRule(2, this.b.getId());
            layoutParams3.addRule(13, -1);
            layoutParams3.leftMargin = PopupUtil.convertDpInPixels(ArcGISMediaFullScreenPageAdapter.this.b, 20);
            layoutParams3.rightMargin = PopupUtil.convertDpInPixels(ArcGISMediaFullScreenPageAdapter.this.b, 20);
            layoutParams3.bottomMargin = PopupUtil.convertDpInPixels(ArcGISMediaFullScreenPageAdapter.this.b, 50);
            layoutParams3.topMargin = PopupUtil.convertDpInPixels(ArcGISMediaFullScreenPageAdapter.this.b, 50);
            synchronized (mediaView.g()) {
                if (!ArcGISMediaAdapter.MediaView.STATUS.LOADED.equals(mediaView.g())) {
                    final View imageView = new ImageView(getContext());
                    ((ImageView) imageView).setImageDrawable(new ProgressBar(getContext()).getProgressDrawable());
                    layoutParams = layoutParams3;
                    mediaView.l = new ArcGISMediaAdapter.MediaView.LoadStatusListener() { // from class: com.esri.android.map.popup.ArcGISMediaFullScreenPageAdapter.a.4
                        @Override // com.esri.android.map.popup.ArcGISMediaAdapter.MediaView.LoadStatusListener
                        public void onLoadStatusChanged(ArcGISMediaAdapter.MediaView.STATUS status) {
                            if (ArcGISMediaAdapter.MediaView.STATUS.LOADED.equals(status)) {
                                a.this.removeView(imageView);
                                a.this.addView(a.this.a(arcGISPopupStyle, mediaView, i), layoutParams);
                            }
                        }
                    };
                    a = imageView;
                } else {
                    layoutParams = layoutParams3;
                    a = a(arcGISPopupStyle, mediaView, i);
                }
            }
            addView(a, layoutParams);
            this.b.setTypeface(arcGISPopupStyle.getMediaCaptionFontType(), arcGISPopupStyle.getMediaCaptionFontStyle());
            this.b.setTextSize(1, arcGISPopupStyle.getMediaCaptionFontSize());
            this.b.setTextColor(arcGISPopupStyle.getMediaCaptionColor());
            this.b.setText(ArcGISMediaFullScreenPageAdapter.this.a.b.formatValue(ArcGISMediaFullScreenPageAdapter.this.a.getItem(i).getCaption(), null));
            this.b.setGravity(1);
            this.b.setLines(2);
            this.b.setEllipsize(TextUtils.TruncateAt.END);
            RelativeLayout.LayoutParams layoutParams4 = new RelativeLayout.LayoutParams(-1, PopupUtil.convertDpInPixels(ArcGISMediaFullScreenPageAdapter.this.b, 80));
            layoutParams4.alignWithParent = true;
            layoutParams4.addRule(12);
            addView(this.b, layoutParams4);
            this.b.setOnClickListener(new View.OnClickListener() { // from class: com.esri.android.map.popup.ArcGISMediaFullScreenPageAdapter.a.5
                private TextView d;

                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    TextView textView3;
                    float measureText = a.this.b.getPaint().measureText((String) a.this.b.getText());
                    double width = view.getWidth();
                    Double.isNaN(width);
                    if (measureText < width * 1.99d) {
                        return;
                    }
                    int convertDpInPixels = PopupUtil.convertDpInPixels(ArcGISMediaFullScreenPageAdapter.this.b, Math.min(350, (int) ((measureText / view.getWidth()) * 55.0f)));
                    if (a.this.c == null || (textView3 = this.d) == null) {
                        a.this.c.setBackgroundColor(arcGISPopupStyle.getPopupBackgroundColor());
                        TextView textView4 = new TextView(a.this.getContext());
                        this.d = textView4;
                        textView4.setTextSize(arcGISPopupStyle.getMediaFullScreenCaptionFontSize());
                        this.d.setTextColor(arcGISPopupStyle.getMediaFullScreenCaptionColor());
                        this.d.setTypeface(arcGISPopupStyle.getMediaFullScreenCaptionFontType(), arcGISPopupStyle.getMediaFullScreenCaptionFontStyle());
                        this.d.setBackgroundColor(arcGISPopupStyle.getPopupBackgroundColor());
                        this.d.setText(((TextView) view).getText());
                        this.d.setGravity(17);
                        a.this.c.addView(this.d, new RelativeLayout.LayoutParams(-1, -1));
                        RelativeLayout.LayoutParams layoutParams5 = new RelativeLayout.LayoutParams(-1, convertDpInPixels);
                        layoutParams5.alignWithParent = true;
                        layoutParams5.addRule(12);
                        a aVar = a.this;
                        aVar.addView(aVar.c, layoutParams5);
                        this.d.setOnClickListener(new View.OnClickListener() { // from class: com.esri.android.map.popup.ArcGISMediaFullScreenPageAdapter.a.5.1
                            @Override // android.view.View.OnClickListener
                            public void onClick(View view2) {
                                a.this.c.setVisibility(8);
                            }
                        });
                        return;
                    }
                    textView3.setText(((TextView) view).getText());
                    a.this.c.setVisibility(0);
                    RelativeLayout.LayoutParams layoutParams6 = new RelativeLayout.LayoutParams(-1, convertDpInPixels);
                    layoutParams6.alignWithParent = true;
                    layoutParams6.addRule(12);
                    a.this.c.setLayoutParams(layoutParams6);
                    a.this.c.invalidate();
                    a.this.requestLayout();
                }
            });
        }
    }
}
